<template>
  <div>
    <div class="footer">
      <!-- 这个是购物车 -->
      <div class="box">
        <div class="car">
          <div class="car2">
            <van-icon
              @click="show = !show"
              name="shopping-cart chat-o"
              :badge="gengxin"
            />
          </div>
        </div>

        <div class="zongji">
          ￥<span>{{ gengxinprice }}</span>
        </div>
        <div class="peisong">另需要配送费￥4元</div>
        <!-- 弹窗 -->
      </div>
      <div class="pos11">
        <div
          v-if="gengxinprice==0? true : false"
          style="background: #2b343d"
          class="qisong1"
        >
          ￥30起送
        </div>
        <div
          v-if="gengxinprice < 30&&gengxinprice>0 ? true : false"
          style="background: orange"
          class="qisong2"
        >
          还差{{ (30 - gengxinprice).toFixed(2) }}元
        </div>
        <div
          v-if="gengxinprice > 30 ? true : false"
          style="background: blue"
          class="qisong3"
        >
          结算
        </div>
      </div>
    </div>
    <!-- 弹窗 -->
    <div v-show="show" class="tanchuang1"></div>
    <div v-show="show" class="tanchuang2">
      <div class="list">
        <div>全部商品</div>
        <div @click="fn">清空</div>
      </div>
      <div v-for="(value, i) in info" :key="i">
        <div class="box">
          <img :src="value.imgUrl" alt="" />
          <div style="width: 100%">
            <h2>{{ value.name }}</h2>
            <div class="st0">{{ value.goodsDesc }}</div>
            <div class="st2">月售{{ value.sellCount }}好评率100%</div>
            <div class="box44">
              <div class="st3">￥{{ value.price }}</div>
              <div class="btn">
                <!-- 设置点击事件 传递它的id和改变的数量 -->
                <button
                  v-if="value.num < 1 ? false : true"
                  @click.stop="jianshao(value.id, -1)"
                >
                  -
                </button>
                <input
                  v-if="value.num < 1 ? false : true"
                  type="text"
                  :value="value.num"
                />
                <button @click.stop="jianshao(value.id, +1)">+</button>
              </div>
            </div>
            <!-- 加减数量 -->
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      show: false,
    };
  },
  //这是过滤出来的属性呢

  computed: {
    info() {
      return this.$store.getters.getlfliter;
    },

    //拿到更新后的长度
    gengxin() {
      let totalnum = 0;
      this.$store.getters.getlfliter.forEach((item) => {
        totalnum += item.num;
      });
      return totalnum;
    },

    //计算总价
    gengxinprice() {
      let totalnum2 = 0;
      this.$store.getters.getlfliter.forEach((item) => {
        totalnum2 += item.price * item.num;
      });
      return totalnum2.toFixed(2);
    },
  },

  methods: {
    //这是点击购物车的数量的改变传递的函数
    jianshao(id, num) {
      //拿到它的值以后就传给vuex来改变它的值
      this.$store.commit("CHANGECLICK", { id, num });
    },
    //便利筛选出来的数组
    fn() {
      //清空所有
 this.$store.getters.getlfliter.forEach((item) => {
         item.num=0;
         this.show=false
      });
    },
  },
};
</script>

<style lang="less" scoped>
.pos11 {
  line-height: 60px;
  div {
    line-height: 60px;
    text-align: center;
    width: 100px;
  }
}
.tanchuang1 {
  position: fixed;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.7);
}
.tanchuang2 {
  position: fixed;
  height: 30%;
  width: 100%;
  bottom: 60px;
  
  background: #ffffff;
  overflow: scroll;
}
.list {
  display: flex;
  justify-content: space-between;
  padding: 0 15px;
  box-sizing: border-box;
  background: #eee;
  color: orange;
  line-height: 30px;
}

.footer {
  height: 60px;
  background: #131d26;
  width: 100%;
  color: #8e9296;
  display: flex;
  justify-content: center;
  position: relative;
  z-index: 5;
}

.box {
  flex: 1;
  display: flex;
  align-items: center;
  text-align: right;
  padding-top: 5px;
  box-sizing: border-box;
  .zongji {
    width: 165px;
    font-size: 20px;
    padding-right: 8px;
    box-sizing: border-box;
    border-right: 1px solid #ccc;
  }
  .peisong {
    font-size: 10px;
    padding-left: 4px;
    box-sizing: border-box;
  }
}
.box:nth-child(1) {
  width: 100px;
}

.car {
  height: 65px;
  width: 65px;
  border-radius: 50%;
  position: absolute;
  top: -10px;
  left: 16px;
  background: #131d26;
  display: flex;
  justify-content: center;
  align-items: center;

  .car2 {
    border-radius: 50%;
    height: 50px;
    width: 50px;
    background: #2b343d;
    display: flex;
    justify-content: center;
    align-items: center;
    i {
      font-size: 30px;
    }
  }
}

.qisong {
  background: #2b343d;
  height: 100%;
  width: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

//新的
.box {
  display: flex;
  width: 100%;
  align-items: center;
  img {
    width: 70px;
    height: 70px;
    justify-content: center;
    align-items: center;
    margin-right: 4px;
  }
}
.box1 {
  position: relative;
  div {
    padding-top: 6px;
    box-sizing: border-box;
    width: 100%;
  }
}
h2 {
  box-sizing: border-box;
  font-weight: bold;
  font-size: 14px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  width: 100%;
}
.st1 {
  font-size: 12px;
  color: #a3a6af;
  padding-top: 6px;
  box-sizing: border-box;
  width: 100%;
}
.st0 {
  font-size: 12px;
  color: #a3a6af;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  width: 190px;
  padding-top: 6px;
  box-sizing: border-box;
}
.st2 {
  font-size: 12px;
  color: #a3a6af;
  padding-top: 6px;
  box-sizing: border-box;
  width: 100%;
  white-space: nowrap;
}
.st3 {
  font-size: 16px;
  color: red;
  padding-top: 6px;
  box-sizing: border-box;
  padding-right: 100px;
}
.st4 {
  text-indent: 6px;
  line-height: 20px;
  background: #f4f5f7;
  border: 1px solid #e1e3e7;
  color: #a8acb0;
}

.box11 {
  display: flex;
  height: 100%;
  width: 100%;
}
.box44 {
  width: 100%;
  display: flex;
  justify-content: space-between;
}
.btn {
  display: flex;
  height: 26px;
  box-sizing: border-box;
  input {
    width: 25px;
    height: 20px;
    text-align: center;
    margin: 0px 10px;
  }

  button {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 22px;
    width: 22px;
    list-style: none;
    border-radius: 12px;
    border: 1px solid #cccccc;
    text-align: center;
  }
}
</style>